package cn.dxc.demo.common;

import com.alibaba.fastjson.JSONObject;
import com.zhenzi.sms.ZhenziSmsClient;

import java.util.HashMap;

public class VerifyCodeUtil {

    public static Object verifySend(String phone,String code){
        ZhenziSmsClient client = new ZhenziSmsClient(
                "https://sms_developer.zhenzikj.com",
                "108623",
                "M2NiNTBjNjEtNzA1Zi00NzBhLTllNTMtNjMzMTNjMjIyNWM0");
        //初始化Client
        final HashMap<String, Object> params = new HashMap<>();
        String result = "";
        // 手机号码
        params.put("number",phone);
        // 模板标号，固定
        params.put("templateId",4520);
        String[] templateParams = new String[2];
        // 获取随机验证码
        templateParams[0] = code;

        templateParams[1] = "10分钟";
        params.put("templateParams", templateParams);
        try {
            result = client.send(params);
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //先将这条数据解析为JSONObject
        final JSONObject outJson  = JSONObject.parseObject(result);
        final HashMap<String, Object> map = new HashMap<>();
        map.put("code",outJson.get("code"));
        map.put("data",outJson.get("data"));
        return map;
    }
}
